How can l use the pre

您所在的位置:网站首页 resnet152 pytorch How can l use the pre

How can l use the pre

2024-05-16 20:29| 来源: 网络整理| 查看: 265

Have you run the code? There are several mistakes. First, resnet152.children() is a generator, and hence is not subscriptable. Also, resnet152 doesn’t take a requires_grad argument. The following code will work:

import torch import torch.nn as nn import torchvision.models as models from torch.autograd import Variable resnet152 = models.resnet152(pretrained=True) modules=list(resnet152.children())[:-1] resnet152=nn.Sequential(*modules) for p in resnet152.parameters(): p.requires_grad = False

Of course, the outcome depends on what you want to achieve. This code returns a model consisting of all layers of resnet152 bar the last one (a fully connected layer), with fixed parameters



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3